Skip to content

[feature] Enhance dev-tools:sync to merge and normalize .gitignore entries#21

Merged
coisa merged 5 commits intomainfrom
feature/12-sync-gitignore
Apr 9, 2026
Merged

[feature] Enhance dev-tools:sync to merge and normalize .gitignore entries#21
coisa merged 5 commits intomainfrom
feature/12-sync-gitignore

Conversation

@coisa
Copy link
Copy Markdown
Contributor

@coisa coisa commented Apr 9, 2026

Summary

  • Added GitIgnore namespace with dedicated classes for .gitignore synchronization:
    • Reader: reads .gitignore entries from both package and project
    • Classifier: classifies entries as directories or files
    • Merger: merges, deduplicates, and sorts entries
    • Writer: writes normalized .gitignore file
  • Updated SyncCommand to orchestrate .gitignore synchronization
  • Entries are sorted: directories first, then files, alphabetical within each group

Changes

  • Created src/GitIgnore/Reader.php - reads .gitignore entries
  • Created src/GitIgnore/Classifier.php - classifies entries as directory/file
  • Created src/GitIgnore/Merger.php - merges and sorts entries
  • Created src/GitIgnore/Writer.php - writes normalized output
  • Updated SyncCommand to call syncGitIgnore() method
  • Created src/Command/GitIgnoreCommand.php - standalone command for .gitignore operations
  • Added comprehensive PHPDoc documentation to all GitIgnore classes (interface, implementation, command, and tests)
  • Updated README.md to include new gitignore command
  • Updated Sphinx documentation with new command reference

Architecture

The implementation follows the acceptance criteria requirements:

  1. Separate dedicated classes - Each responsibility is isolated in its own class
  2. Command as orchestrator - The command layer only orchestrates, no core logic
  3. Loose coupling - Classes can be reused by other commands/tools/packages
  4. Deterministic output - Always sorted: directories first, then files, alphabetically

Example

If dev-tools has:
.idea/ .vscode/ vendor/ .DS_Store *.cache

And project has:
tmp/ vendor/ composer.lock

The synced result will be:
.idea/ tmp/ vendor/ .vscode/ *.cache .DS_Store composer.lock

New Command

The gitignore command can be used standalone:

# Merge and sync .gitignore files
composer dev-tools gitignore

# Specify custom source and target paths
composer dev-tools gitignore -- --source=/path/to/source/.gitignore --target=/path/to/target/.gitignore

Testing

All tests pass (125 tests, 306 assertions) with 85.89% code coverage.

Closes #12

- Add GitIgnore namespace with Reader, Classifier, Merger, Writer classes
- Reader reads .gitignore entries from both package and project
- Classifier classifies entries as directories or files
- Merger merges, deduplicates, and sorts entries
- Writer writes normalized .gitignore file
- SyncCommand now syncs .gitignore entries automatically
- Entries are sorted: directories first, then files, alphabetical within each group
- Transform magic strings into private constants in Classifier

Implements: #12
@coisa coisa force-pushed the feature/12-sync-gitignore branch from e78bbda to 2674281 Compare April 9, 2026 12:19
coisa added 4 commits April 9, 2026 13:16
… .gitignore management

- Added GitIgnoreInterface to define the contract for .gitignore files.
- Implemented Merger and MergerInterface for merging and deduplicating .gitignore entries.
- Created Reader and ReaderInterface for reading .gitignore files.
- Developed Writer and WriterInterface for writing .gitignore files.
- Updated existing classes to utilize the new interfaces and improve functionality.
- Added tests for GitIgnore, Merger, Reader, and Writer to ensure correct behavior.
- Enhanced command tests to cover new GitIgnoreCommand functionality.

Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
…nore files

Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
Signed-off-by: Felipe Sayão Lobato Abreu <github@mentordosnerds.com>
@coisa coisa merged commit 44eb6b8 into main Apr 9, 2026
5 checks passed
@coisa coisa deleted the feature/12-sync-gitignore branch April 9, 2026 16:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Enhance dev-tools:sync to merge and normalize .gitignore entries from the dev-tools repository

1 participant